/**
 *
 * @param {import('webpack').Module} module
 * @returns
 */
function fnm(module) {
  const { dependencies, type, resource } = module;
  return {
    resource,
    dependencies: (() => {
      let set = new Set();
      set.size;
      if (!dependencies || !dependencies.size) {
        return null;
      }
      const deps = [].map.call(dependencies, (dep) => dep.userRequest || dep.request).filter((e) => e);
      return Array.from(new Set(deps));
    })(),
  };
}

/**
 *
 * @param {Iterable<import('webpack').Module>} modules
 * @returns
 */
function fnm_s(modules) {
  return [].map.call(modules, (m) => fnm(m));
}

module.exports.fnm = fnm;
module.exports.fnm_s = fnm_s;

exports.callOnce = (() => {
  const flagCache = {};
  /**
   * @param {string|number|symbol} key
   * @param {()=>void} fn
   */
  return function (fn, key) {
    if (flagCache[key]) {
      return;
    }
    flagCache[key] = true;
    fn();
  };
})();
